import {
  isPlainObject
} from './utils'

const asyncFn = async function () {}

export function wrapFn (fn) {
  if (asyncFn.constructor === fn.constructor) {
    return async function () {
      const res = await fn.apply(this, arguments)
      if (isPlainObject(res) && res.msg) {
        res.message = res.msg
        // delete res.msg
      }
      return res
    }
  }
  return function () {
    const res = fn.apply(this, arguments)
    if (isPlainObject(res) && res.msg) {
      res.message = res.msg
      // delete res.msg
    }
    return res
  }
}
